package cloudUser.controller;

import cloudEntity.dto.user.SmartRoleInsertDTO;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.PageBeanVO;
import cloudUser.service.SmartUserRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cloudEntity.vo.user.SmartUserRoleVO;
import cloudEntity.dto.user.SmartRoleUpdateDTO;

/**
 * @program: Smart School
 * @ClassName RoleController
 * @description:
 * @author: 陈智博
 * @create: 2025-05-15 20:29
 * @Version 1.0
 **/
@RestController
@RequestMapping("/role")
@Tag(name = "角色控制器")
public class RoleController {

    @Autowired
    private SmartUserRoleService smartUserRoleService;

    @Operation(summary = "分页查询用户角色")
    @Parameters({
            @Parameter(name = "n",description = "页码",required = false),
            @Parameter(name = "s",description = "条数",required = false)
    })
    @RequestMapping(method = RequestMethod.GET,value = "/page")
    public ResultUtils selectRoleByTypeReturnPageInfo(@RequestParam(value = "n",required = false,defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "s",required = false,defaultValue = "5") Integer pageSize)
    {
        PageBeanVO<SmartUserRoleVO> smartUserEntityPageBeanVO = smartUserRoleService.GetSmartRoleReturnPage( pageNum, pageSize);
        return ResultUtils.success(smartUserEntityPageBeanVO);
    }

    @Operation(summary = "新增用户角色")
    @Parameter(name = "smartRoleDTO",description = "智慧校园新增角色DTO",required = true)
    @RequestMapping(method = RequestMethod.POST,value = "/insert")
    public ResultUtils InsertRole(@RequestBody SmartRoleInsertDTO smartRoleInsertDTO)
    {
        Integer i = smartUserRoleService.InsertRoleActor(smartRoleInsertDTO);
        if(i>0)
        {
            return  ResultUtils.success("新增记录成功!");
        }
        return ResultUtils.failed("新增记录失败!");
    }

    @Operation(summary = "修改用户角色")
    @Parameter(name = "smartRoleUpdateDTO",description = "智慧校园修改角色DTO",required = true)
    @RequestMapping(method = RequestMethod.PUT,value = "/update")
    public ResultUtils UpdateRole(@RequestBody SmartRoleUpdateDTO smartRoleUpdateDTO)
    {
        Integer i = smartUserRoleService.UpdateRole(smartRoleUpdateDTO);
        if(i>0)
        {
            return ResultUtils.success("修改记录成功!");
        }
        return ResultUtils.failed("修改记录失败!");
    }

    @Operation(summary = "删除用户角色")
    @RequestMapping(method = RequestMethod.DELETE,value = "/delete")
    public ResultUtils DeleteRole(@RequestParam("ids") Integer ids)
    {
        Integer i = smartUserRoleService.DeleteRole(ids);
        if(i>0)
        {
            return ResultUtils.success("删除记录成功!");
        }
        return ResultUtils.failed("删除记录失败!");
    }

}
